﻿using B.S.Databasic.Api.Read.Application.Command.Account;
using B.S.Databasic.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Databasic.Api.Read.Controllers
{
    /// <summary>
    /// 用户控制(读)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public AccountController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 用户查询分页列表
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询分页后的数据统一包装分页类</returns>
        [HttpGet]
        [Authorize]
        public async Task<ApiPageing<AccountDTO>> GetAccountPage([FromQuery] GetAccountPageCommand request)
        {
            var result = await mediator.Send(request);
            return result;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="command">登录命令</param>
        /// <returns>登录结果，包含用户信息和角色</returns>
        [HttpGet]
        public async Task<ApiResult<AccountLoginDTO>> Login([FromQuery] LoginCommand command)
        {

            var result = await mediator.Send(command);
            return result;
        }
    }
}
